package com.hqd.ch03.test.post;

import com.hqd.ch03.bean.Car;
import com.hqd.ch03.v13.config.BeanPostProcessor;
import org.apache.commons.lang3.StringUtils;

public class CarBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        System.out.println("初始化前");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        if (StringUtils.equals(beanName, "car") && bean instanceof Car) {
            Car car = (Car) bean;
            System.out.println("修改前：" + car);
            car.setBrand("帕拉梅拉");
            car.setPrice(9999.99);
            System.out.println("修改后：" + car);
        }
        System.out.println("初始化后");
        return bean;
    }
}

